# -*- coding: utf-8 -*-

from odoo import api, fields, models, _


# 里是对楼宇、房间表、床位表的model

class Build(models.Model):
    # 楼宇
    _name = 'res.build'
    _rec_name = 'building_name'

    building_name = fields.Char(u'楼宇名称')
    building_num = fields.Char(u'楼层数')

    room_ids = fields.One2many('res.room', 'build', string=u"房间")


class BuildRoom(models.Model):
    # 房间
    _name = 'res.room'
    _rec_name = 'room_num'

    room_num = fields.Integer(u'房间号')
    unit_name = fields.Char(u'单元号')
    room_ori = fields.Char(u'朝向')
    bed_num = fields.Char(u'床位数')
    room_money = fields.Float(u'房费')
    build = fields.Many2one('res.build', string=u"楼宇")
    bed_ids = fields.One2many('res.bed', 'room', string=u"床位")

    @api.multi
    def name_get(self):
        result = []
        for r in self:
            result.append((r.id, "%s %d房" % (r.build.building_name, r.room_num)))
        return result


class Bed(models.Model):
    # 床位
    _name = 'res.bed'
    _rec_name = 'bed_num'

    bed_id = fields.Integer(u'床位ID')
    bed_num = fields.Integer(u'床位号')
    bed_money = fields.Float(u'床位费')

    room = fields.Many2one('res.room', string=u"房间")

    @api.multi
    def name_get(self):
        result = []
        for b in self:
            result.append((b.id, "%s %d房 %d床" % (b.room.build.building_name, b.room.room_num, b.bed_num)))
        return result
